/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package upc.com.pc2.service;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import upc.com.pc2.Alumnos;

/**
 *
 * @author JORGELUIS
 */
@Stateless
@Path("upc.com.pc2.alumnos")
public class AlumnosFacadeREST extends AbstractFacade<Alumnos> {
    @PersistenceContext(unitName = "JORGEREYESPC2PU")
    private EntityManager em;

    public AlumnosFacadeREST() {
        super(Alumnos.class);
    }

  @POST
    @Path("POST/Alumnos")
    @Override
    @Consumes({"application/xml", "application/json"})
    public void create(Alumnos entity) {
        super.create(entity);
    }

  
    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(Alumnos entity) {
        super.edit(entity);
    }

   /* @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") String id) {
        super.remove(super.find(id));
    }*/

    
   @GET
    @Path("Alumnos/{id}")
    @Produces({"application/xml", "application/json"})
    public Alumnos find(@PathParam("id") String id) {
        return super.find(id);
    }

    @GET
    @Path("GET/Alumnos")
    @Produces({"application/xml", "application/json"})
    public List<Alumnos> findAll() {
        return super.findAll();
    }

  @PUT
    @Path("PUT/Alumnos/{id}")
    @Consumes({"application/xml", "application/json"})
    public void editStudents(Alumnos entity) {
        super.edit(entity);
    }
    
    @DELETE
    @Path("DELETE/Alumnos/{id}")
    public void removeStudent(@PathParam("id") String id) {
        super.remove(super.find(id));
    }
    
  /*  @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<Alumnos> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }*/

    /*@GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }*/

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
   @GET
    @Path("Query/{lastName}/{firstName}")
    @Produces({"application/xml", "application/json"})
    public List<Alumnos> consulta1(@PathParam("lastName") String lastName, @PathParam("firstName") String firstName) {
        Query q = em.createQuery("SELECT s FROM Alumnos s WHERE s.firstName = :firstName AND s.lastName = :lastName");
        q.setParameter("lastName", lastName);
        q.setParameter("firstName", firstName);
        return q.getResultList();
    }
    
}
